```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java NIO Selector 高性能网络编程指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f9f9f9;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', Georgia, serif;
            font-weight: 600;
            color: #222;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            border-radius: 8px;
            color: #f8f8f2;
            overflow-x: auto;
        }
        .highlight-box {
            border-left: 4px solid #4f46e5;
            background-color: rgba(79, 70, 229, 0.05);
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .icon-box {
            width: 60px;
            height: 60px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20px;
        }
        .nav-link {
            position: relative;
        }
        .nav-link:after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: 0;
            left: 0;
            background-color: #4f46e5;
            transition: width 0.3s ease;
        }
        .nav-link:hover:after {
            width: 100%;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <div class="flex items-center mb-4">
                        <span class="bg-white text-indigo-600 px-3 py-1 rounded-full text-sm font-medium">技术专题</span>
                        <span class="ml-3 text-indigo-200">Java 高性能编程</span>
                    </div>
                    <h1 class="text-4xl md:text-5xl font-bold leading-tight mb-6">深入理解 Java NIO Selector</h1>
                    <p class="text-xl text-indigo-100 mb-8">高性能网络编程的核心组件：揭秘 Selector 的工作原理与实践应用</p>
                    <div class="flex space-x-4">
                        <a href="#intro" class="bg-white text-indigo-600 hover:bg-gray-100 px-6 py-3 rounded-lg font-medium transition-colors duration-300 flex items-center">
                            <i class="fas fa-book-open mr-2"></i> 开始阅读
                        </a>
                        <a href="#code-example" class="border-2 border-white text-white hover:bg-white hover:text-indigo-600 px-6 py-3 rounded-lg font-medium transition-colors duration-300 flex items-center">
                            <i class="fas fa-code mr-2"></i> 查看代码
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white bg-opacity-10 p-6 rounded-2xl backdrop-blur-sm border border-white border-opacity-20">
                        <div class="mermaid">
                            graph TD
                            A[Selector] --> B[Channel 1]
                            A --> C[Channel 2]
                            A --> D[Channel 3]
                            A --> E[...]
                            B -->|可读事件| F[处理读操作]
                            C -->|可写事件| G[处理写操作]
                            D -->|连接事件| H[处理新连接]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="bg-white shadow-sm sticky top-0 z-10">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex justify-between items-center py-4">
                <div class="text-xl font-bold text-indigo-600">NIO Selector</div>
                <div class="hidden md:flex space-x-8">
                    <a href="#intro" class="nav-link py-2">核心概念</a>
                    <a href="#working" class="nav-link py-2">工作原理</a>
                    <a href="#practice" class="nav-link py-2">实践应用</a>
                    <a href="#alternatives" class="nav-link py-2">替代方案</a>
                </div>
                <button class="md:hidden text-gray-600">
                    <i class="fas fa-bars text-2xl"></i>
                </button>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container mx-auto max-w-6xl px-4 py-12">
        <!-- Introduction Section -->
        <section id="intro" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-indigo-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-700">核心概念</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md p-8 card">
                    <div class="icon-box bg-indigo-100 text-indigo-600">
                        <i class="fas fa-project-diagram text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-4">什么是 Selector？</h3>
                    <p class="text-gray-600">Selector 是 Java NIO 中的多路复用器，它允许单个线程监控多个 Channel 的 I/O 状态。就像一个"管家"，负责监控多个"房间"(Channel)的状态，只有当某个房间有"事件"发生时，才会通知你去处理。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-8 card">
                    <div class="icon-box bg-purple-100 text-purple-600">
                        <i class="fas fa-bolt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-4">Selector 解决的问题</h3>
                    <p class="text-gray-600">传统的阻塞 I/O 模型中，每个连接需要一个专门的线程，导致：线程资源消耗过大、线程切换开销增加、系统性能下降。Selector 通过事件驱动的方式，让一个线程可以处理多个连接，大大提高并发能力。</p>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6">
                    <h4 class="font-semibold text-lg mb-4 text-indigo-600">传统阻塞 I/O 模型</h4>
                    <div class="code-block p-4 mb-4">
                        <pre><code class="language-java">// 传统阻塞 I/O 模型（伪代码）
while (true) {
    Socket socket = serverSocket.accept(); // 阻塞等待连接
    new Thread(() -> {
        try {
            handleConnection(socket); // 每个连接一个线程
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).start();
}</code></pre>
                    </div>
                    <div class="p-4 bg-red-50 rounded-lg border-l-4 border-red-400">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 text-red-400">
                                <i class="fas fa-exclamation-circle"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-red-700">当连接数量增加到数千甚至数万时，这种模型会导致严重的性能问题。</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="code-example" class="bg-white rounded-xl shadow-md p-6">
                    <h4 class="font-semibold text-lg mb-4 text-indigo-600">NIO 模型 (Selector)</h4>
                    <div class="code-block p-4">
                        <pre><code class="language-java">// NIO 模型（简化版）
Selector selector = Selector.open();
ServerSocketChannel serverChannel = ServerSocketChannel.open();
serverChannel.configureBlocking(false);
serverChannel.register(selector, SelectionKey.OP_ACCEPT);

while (true) {
    selector.select(); // 阻塞，直到有事件发生
    Set&lt;SelectionKey&gt; selectedKeys = selector.selectedKeys();
    
    for (SelectionKey key : selectedKeys) {
        if (key.isAcceptable()) {
            // 处理新连接
        } else if (key.isReadable()) {
            // 处理读事件
        }
        // ...
    }
    selectedKeys.clear();
}</code></pre>
                    </div>
                    <div class="p-4 bg-green-50 rounded-lg border-l-4 border-green-400 mt-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 text-green-400">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-green-700">这种模式可以用少量线程处理大量连接，大大提高了系统的并发处理能力。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Working Principle Section -->
        <section id="working" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-indigo-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-700">工作原理与源码解析</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">Selector 的内部实现</h3>
                    <p class="text-gray-600 mb-6">Selector 的实现依赖于操作系统的 I/O 多路复用机制，如 Linux 的 epoll、Windows 的 IOCP、macOS 的 kqueue 等。Java NIO 通过 JNI 调用这些底层机制，实现了跨平台的多路复用能力。</p>
                    
                    <div class="code-block p-4 mb-6">
                        <pre><code class="language-java">// EPollSelectorImpl 的简化版源码分析
public class EPollSelectorImpl extends SelectorImpl {
    private final int epfd; // epoll 文件描述符
    private final int eventsfd; // 事件数组文件描述符
    
    // 注册通道
    @Override
    protected void implRegister(SelectionKeyImpl ski) {
        // 调用 epoll_ctl 添加监听的文件描述符
        EPollArrayWrapper.epollCtl(epfd, EPOLL_CTL_ADD, fd, events);
    }
    
    // 选择准备好的通道
    @Override
    protected int doSelect(long timeout) {
        // 调用 epoll_wait 等待事件
        int numEvents = EPollArrayWrapper.epollWait(epfd, eventsfd, timeout);
        // 处理返回的事件...
        return numEvents;
    }
}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">SelectionKey：事件与通道的桥梁</h3>
                    <p class="text-gray-600 mb-4">SelectionKey 是 Channel 注册到 Selector 后返回的句柄，它包含了 Channel 的信息、感兴趣的事件以及附加的对象等。</p>
                    
                    <div class="highlight-box p-6 mb-6">
                        <h4 class="font-semibold mb-3">SelectionKey 的核心方法：</h4>
                        <ul class="space-y-2 text-gray-700">
                            <li><span class="font-medium text-indigo-600">selector()</span> - 获取关联的 Selector</li>
                            <li><span class="font-medium text-indigo-600">channel()</span> - 获取关联的 Channel</li>
                            <li><span class="font-medium text-indigo-600">interestOps()</span> - 获取感兴趣的事件集合</li>
                            <li><span class="font-medium text-indigo-600">readyOps()</span> - 获取已就绪的事件集合</li>
                            <li><span class="font-medium text-indigo-600">isReadable()/isWritable()</span> - 判断特定事件是否就绪</li>
                            <li><span class="font-medium text-indigo-600">attach()/attachment()</span> - 附加对象相关方法</li>
                        </ul>
                    </div>
                    
                    <div class="mermaid bg-white p-6 rounded-xl shadow-sm">
                        sequenceDiagram
                            participant Client
                            participant Channel
                            participant Selector
                            participant SelectionKey
                            Client->>Channel: 发起I/O操作
                            Channel->>Selector: 触发事件
                            Selector->>SelectionKey: 更新就绪状态
                            Application->>Selector: select()调用
                            Selector->>Application: 返回就绪的SelectionKey
                            Application->>Channel: 通过SelectionKey处理I/O
                    </div>
                </div>
            </div>
        </section>

        <!-- Practical Application Section -->
        <section id="practice" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-indigo-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-700">使用 Selector 构建高性能网络应用</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600">基本使用步骤</h3>
                <div class="grid md:grid-cols-5 gap-6 mb-8">
                    <div class="col-span-1 bg-indigo-50 p-4 rounded-lg flex flex-col items-center text-center">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600 mb-3">
                            <span class="font-bold">1</span>
                        </div>
                        <p class="text-sm font-medium">创建 Selector</p>
                    </div>
                    <div class="col-span-1 bg-indigo-50 p-4 rounded-lg flex flex-col items-center text-center">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600 mb-3">
                            <span class="font-bold">2</span>
                        </div>
                        <p class="text-sm font-medium">创建并配置 Channel</p>
                    </div>
                    <div class="col-span-1 bg-indigo-50 p-4 rounded-lg flex flex-col items-center text-center">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600 mb-3">
                            <span class="font-bold">3</span>
                        </div>
                        <p class="text-sm font-medium">注册到 Selector</p>
                    </div>
                    <div class="col-span-1 bg-indigo-50 p-4 rounded-lg flex flex-col items-center text-center">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600 mb-3">
                            <span class="font-bold">4</span>
                        </div>
                        <p class="text-sm font-medium">等待事件</p>
                    </div>
                    <div class="col-span-1 bg-indigo-50 p-4 rounded-lg flex flex-col items-center text-center">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-600 mb-3">
                            <span class="font-bold">5</span>
                        </div>
                        <p class="text-sm font-medium">处理事件</p>
                    </div>
                </div>

                <div class="code-block p-4 mb-6">
                    <pre><code class="language-java">// 简单的 NIO Echo 服务器示例
public class NIOEchoServer {
    private static final int BUFFER_SIZE = 1024;
    private static final int PORT = 8080;
    
    public static void main(String[] args) throws IOException {
        Selector selector = Selector.open();
        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.socket().bind(new InetSocketAddress(PORT));
        serverChannel.configureBlocking(false);
        serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        
        while (true) {
            if (selector.select(1000) == 0) continue;
            
            Set&lt;SelectionKey&gt; selectedKeys = selector.selectedKeys();
            Iterator&lt;SelectionKey&gt; it = selectedKeys.iterator();
            
            while (it.hasNext()) {
                SelectionKey key = it.next();
                it.remove();
                
                try {
                    if (key.isAcceptable()) {
                        handleAccept(key, selector);
                    } else if (key.isReadable()) {
                        handleRead(key);
                    } else if (key.isWritable()) {
                        handleWrite(key);
                    }
                } catch (IOException e) {
                    key.cancel();
                    key.channel().close();
                }
            }
        }
    }
    
    // 处理accept/read/write的方法...
}</code></pre>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-xl font-semibold mb-6 text-indigo-600">性能优化技巧</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white rounded-xl shadow-md p-6 card">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-indigo-100 rounded-lg flex items-center justify-center text-indigo-600 mr-4">
                                <i class="fas fa-memory"></i>
                            </div>
                            <h4 class="font-semibold">使用直接缓冲区</h4>
                        </div>
                        <p class="text-gray-600 text-sm">直接缓冲区可以减少数据复制，提高 I/O 性能</p>
                        <div class="mt-4 code-block p-3 text-sm">
                            ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-md p-6 card">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-purple-100 rounded-lg flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-server"></i>
                            </div>
                            <h4 class="font-semibold">使用多个 Selector</h4>
                        </div>
                        <p class="text-gray-600 text-sm">在多核环境下，可以使用多个 Selector 分担负载</p>
                        <div class="mt-4 code-block p-3 text-sm">
                            Selector[] selectors = new Selector[
                                Runtime.getRuntime().availableProcessors()];
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-md p-6 card">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-red-100 rounded-lg flex items-center justify-center text-red-600 mr-4">
                                <i class="fas fa-bug"></i>
                            </div>
                            <h4 class="font-semibold">避免 Selector 空轮询 bug</h4>
                        </div>
                        <p class="text-gray-600 text-sm">检测并处理 Selector 空轮询导致的 CPU 使用率飙升</p>
                        <div class="mt-4 code-block p-3 text-sm overflow-x-auto">
                            if (emptySelectCount > 10) {
                                // 重建 Selector
                            }
                        </div>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-xl font-semibold mb-6 text-indigo-600">Selector 在实际项目中的应用</h3>
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h4 class="font-semibold mb-3">Netty 中的 Selector 应用</h4>
                        <p class="text-gray-600 mb-4">Netty 是一个高性能的网络应用框架，它在内部大量使用了 Selector。Netty 对 Selector 进行了封装和优化，提供了更易用的 API。</p>
                        
                        <div class="code-block p-4 text-sm">
                            <pre><code class="language-java">// Netty NioEventLoop 核心逻辑
public final class NioEventLoop extends SingleThreadEventLoop {
    private Selector selector;
    
    protected void run() {
        for (;;) {
            int selectedKeys = selector.select(timeoutMillis);
            if (selectedKeys > 0 || hasTasks()) {
                processSelectedKeys(); // 处理I/O事件
                runAllTasks(); // 运行任务队列
            }
        }
    }
    
    private void processSelectedKeys() {
        // 优化的selectedKeys处理逻辑
    }
}</code></pre>
                        </div>
                    </div>
                    <div>
                        <h4 class="font-semibold mb-3">自定义 RPC 框架中的应用</h4>
                        <p class="text-gray-600 mb-4">在自定义 RPC 框架中，我们可以使用 Selector 实现高性能的网络通信层。</p>
                        
                        <div class="code-block p-4 text-sm">
                            <pre><code class="language-java">// 简化的 RPC 服务器核心
public class SimpleRpcServer {
    private Selector selector;
    private ExecutorService threadPool;
    
    public void start() throws IOException {
        selector = Selector.open();
        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.configureBlocking(false);
        serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        
        while (true) {
            selector.select();
            Iterator&lt;SelectionKey&gt; it = selector.selectedKeys().iterator();
            while (it.hasNext()) {
                SelectionKey key = it.next();
                it.remove();
                
                if (key.isAcceptable()) {
                    handleAccept(key);
                } else if (key.isReadable()) {
                    // 提交到线程池处理
                    threadPool.submit(() -> handleRead(key));
                }
            }
        }
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Alternatives Section -->
        <section id="alternatives" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-indigo-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-700">Selector 的局限性与替代方案</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">Selector 的局限性</h3>
                    <div class="bg-white rounded-xl shadow-md p-6">
                        <ul class="space-y-4 text-gray-600">
                            <li class="flex items-start">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mr-3">
                                    <i class="fas fa-exclamation-triangle"></i>
                                </div>
                                <p><span class="font-medium">编程复杂度高</span> - 相比传统的阻塞 I/O，使用 Selector 的代码更加复杂，容易出错</p>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mr-3">
                                    <i class="fas fa-bug"></i>
                                </div>
                                <p><span class="font-medium">调试困难</span> - 非阻塞 I/O 的异步特性使得调试变得困难</p>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mr-3">
                                    <i class="fas fa-sync-alt"></i>
                                </div>
                                <p><span class="font-medium">可能的空轮询问题</span> - 某些 JDK 版本中存在 Selector 空轮询 bug</p>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mr-3">
                                    <i class="fas fa-microchip"></i>
                                </div>
                                <p><span class="font-medium">单线程处理模型</span> - 虽然可以使用多个 Selector，但每个 Selector 仍然是单线程处理的</p>
                            </li>
                        </ul>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">替代方案</h3>
                    <div class="space-y-6">
                        <div class="bg-white rounded-xl shadow-md p-6 card">
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-lg bg-green-100 text-green-600 flex items-center justify-center mr-4">
                                    <i class="fas fa-network-wired"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">Netty</h4>
                                    <p class="text-gray-600 text-sm">Netty 是一个成熟的网络应用框架，它封装了 Selector 的复杂性，提供了更易用的 API。</p>
                                    <div class="mt-3 code-block p-2 text-xs">
                                        EventLoopGroup bossGroup = new NioEventLoopGroup();
                                        ServerBootstrap b = new ServerBootstrap();
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="bg-white rounded-xl shadow-md p-6 card">
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-lg bg-blue-100 text-blue-600 flex items-center justify-center mr-4">
                                    <i class="fas fa-globe"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">Java 11+ 异步 HTTP 客户端</h4>
                                    <p class="text-gray-600 text-sm">Java 11 引入了新的 HTTP 客户端 API，支持异步操作。</p>
                                    <div class="mt-3 code-block p-2 text-xs">
                                        HttpClient client = HttpClient.newHttpClient();
                                        client.sendAsync(request, BodyHandlers.ofString());
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="bg-white rounded-xl shadow-md p-6 card">
                            <div class="flex items-start">
                                <div class="flex-shrink-0 h-10 w-10 rounded-lg bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                    <i class="fas fa-atom"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">Project Loom</h4>
                                    <p class="text-gray-600 text-sm">未来的 Java 版本将引入虚拟线程（纤程），可以用同步的编程模型实现高并发。</p>
                                    <div class="mt-3 code-block p-2 text-xs">
                                        Thread.startVirtualThread(() -> {
                                            handleConnection(socket);
                                        });
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-indigo-50 rounded-xl p-8">
                <div class="flex items-start">
                    <div class="flex-shrink-0 h-12 w-12 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-6">
                        <i class="fas fa-lightbulb text-xl"></i>
                    </div>
                    <div>
                        <h3 class="text-xl font-semibold mb-3">如何选择？</h3>
                        <p class="text-gray-600 mb-4">对于新项目，推荐使用 Netty 等成熟框架，它们已经解决了 NIO 的许多痛点。如果你需要完全控制或学习目的，可以直接使用 NIO Selector。对于未来的项目，可以关注 Project Loom 的发展。</p>
                        <a href="https://netty.io" target="_blank" class="inline-flex items-center text-indigo-600 hover:text-indigo-800 font-medium">
                            了解更多关于 Netty 的信息
                            <i class="fas fa-arrow-right ml-2"></i>
                        </a>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术之美，分享编程之乐</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" target="_blank" class="hover:text-white transition-colors duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```